//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#if !defined (_BATTERY_H_)
#define _BATTERY_H_

#define DUMP_OUT(x) x
#define BAT_DBG(x) //x

#define MAX_NUM 10
//Post Events & Status
//Normal
#define PM_CHARGE_INSERT  0x00000001
#define PM_CHARGE_REMOVE  0x00000002
#define PM_FASTCHG_RDY    0x00000004
#define PM_FASTCHG_FIN    0x00000008
#define PM_CHGWD10S_DEC   0x00000010
#define PM_CHGWD_EXP      0x00000020
#define PM_CHARGE_ERR     0x00000040
#define PM_CHARGE_POT     0x00000080
#define PM_SOFT_LOW_BAT   0x00000100
#define PM_BATTERY_CAP    0x00000200
#define PM_BATTERY_WAKE   0x00000400
//Status
#define PM_BAT_LOWVOL     0x80000000
#define PM_BAT_CRITICAL   0x02000000
#define PM_BAT_HIGHTMP    0x40000000
#define PM_CHARGE_START   0x20000000
#define PM_CHARGE_STOP    0x10000000
#define PM_CHARGER_WALL   0x08000000
#define PM_CHARGER_USB    0x04000000

typedef struct chargeEventNode : public DLinkNode {
    EmIsrParameter isrParameter;
}ChargeEventNode;

class CBattery : public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */ Int64 u64Offset,
        /* [in] */ Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 u64Offset,
        /* [in] */ const MemoryBuf &buffer,
        /* [out] */ Int32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 nControlCode,
        /* [in] */ const MemoryBuf &inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose(){}

    ECode ChargeMgmThread();
    ECode InitChargeEventQueue();

    // Member variables
public:
    DzEvent m_ChargeEvent;
    Int32 m_nVoltage;
    EmIsrParameter CEQueue[MAX_NUM];//charge event node Queue
    UInt32 CEQueueHead;//charge event Queue head;
    UInt32 CEQueueTail;//charge event Queue tail;
    DzTimer *m_reportLBTimer;
};

#endif //_BATTERY_H_
